package com.yy.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.yy.common.Resault;
import com.yy.domain.Bicycle;
import com.yy.domain.Order;
import com.yy.dto.OrderDTO;
import com.yy.mapper.OrderMapper;
import com.yy.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.UUID;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;
    /**
     * @param userId
     * @param bicycleId
     */
    @Override
    public void createOrder(Integer userId, Integer bicycleId) {
        Order order=new Order();
        order.setUserId(userId);
        order.setBicycleId(bicycleId);
        order.setOrderId(UUID.randomUUID().toString().replace("-"," "));
        order.setStartTime(new Date());
        order.setEndTime(new Date());
        order.setCost(0.0);
        order.setRemark("正在使用.......");
        this.orderMapper.insert(order);
    }

    /**
     * @param orderDTO
     * @return
     */
    @Override
    public Resault<List<Order>> queryAllBicycle(OrderDTO orderDTO) {
        PageHelper.startPage(orderDTO.getPageNum(),orderDTO.getPageSize());
        List<Order> positionVoList=orderMapper.selectPositionVoByCondition(orderDTO);
        PageInfo<Order> pageInfo=new PageInfo<>(positionVoList);
        Resault<List<Order>> result=new Resault<>(pageInfo.getTotal(),pageInfo.getList());
        return result;
    }

    /**
     * @param orderId
     * @return
     */
    @Override
    public Order getOrderById(String orderId) {
        return this.orderMapper.selectByPrimaryKey(orderId);
    }

    /**
     * @param order
     */
    @Override
    public void updateOrder(Order order) {
        this.orderMapper.insert(order);

    }
}
